module.exports = {
    configureWebpack: {
        devServer: {
            // port:8888,
            open: true,
            // MOCk接口编写的地方
            before(app) {
                // 用户信息池
                let userPoor=[
                    {username:'quan',password:'123456'},
                    {username:'wei',password:'123456'},
                ]
                // 注册接口
                app.get('/api/register',(req,res)=>{
                    const {username,password}=req.query
                    const userLength=userPoor.filter(v=>v.username===username).length
                    if(userLength>0){
                        res.json({
                            success:false,
                            message:'用户名已存在'
                        })
                    }else{
                        res.json({
                            success:true,
                            message:'注册成功'
                        })
                    }
                })
                // 登陆接口
                let tokenKey='quan'
                app.get('/api/login',(req,res)=>{
                    const {username,password}=req.query
                    if(username==='quan' && password==='123456' || username==='wei' && password==='123456'){
                        res.json({
                            code:0,
                            message:'登陆成功',
                            token:tokenKey + "-" + username + "-" + (new Date().getTime()+60*60*1000)
                        })
                    }else{
                        res.json({
                            code:1,
                            message:'账号或密码错误'
                        })
                    }
                })
                // 首页轮播图数据接口
                app.get('/api/banner',(req,res)=>{
                    res.json({
                        data:[
                            {
                                url:'http://www.baidu.com',
                                image:'/static/slide-1.png'
                            },
                            {
                                url:'http://www.baidu.com',
                                image:'/static/slide-2.png'
                            },
                            {
                                url:'http://www.baidu.com',
                                image:'/static/slide-3.png'
                            },
                        ]
                    })
                })
                // 滚动分类接口
                app.get('/api/rollingList',(req,res)=>{
                    res.json({
                        data:[
                            [
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-1.png',
                                    label:'分类一'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-1.png',
                                    label:'分类一'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-1.png',
                                    label:'分类一'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-1.png',
                                    label:'分类一'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-1.png',
                                    label:'分类一'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-1.png',
                                    label:'分类一'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-1.png',
                                    label:'分类一'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-1.png',
                                    label:'分类一'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-1.png',
                                    label:'分类一'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-1.png',
                                    label:'分类一'
                                },
                            ],
                            [
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-2.png',
                                    label:'分类二'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-2.png',
                                    label:'分类二'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-2.png',
                                    label:'分类二'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-2.png',
                                    label:'分类二'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-2.png',
                                    label:'分类二'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-2.png',
                                    label:'分类二'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-2.png',
                                    label:'分类二'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-2.png',
                                    label:'分类二'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-2.png',
                                    label:'分类二'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-2.png',
                                    label:'分类二'
                                },
                            ],
                            [
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-3.png',
                                    label:'分类三'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-3.png',
                                    label:'分类三'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-3.png',
                                    label:'分类三'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-3.png',
                                    label:'分类三'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-3.png',
                                    label:'分类三'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-3.png',
                                    label:'分类三'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-3.png',
                                    label:'分类三'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-3.png',
                                    label:'分类三'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-3.png',
                                    label:'分类三'
                                },
                                {
                                    url:'http://www.baidu.com',
                                    image:'/static/slide-3.png',
                                    label:'分类三'
                                },
                            ]
                        ]
                    })
                })
                // 获取分类页的分类数据
                app.get('/api/classify',(req,res)=>{
                    switch (req.query.type) {
                        case '0':
                            res.json({
                                data:[
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                    {
                                        image:'/static/category-1.webp',
                                        label:'小米'
                                    },
                                ]
                            })
                        break;
                        case '1':
                            res.json({
                                data:[
                                    {
                                        image:'/static/category-2.webp',
                                        label:'华为'
                                    },
                                    {
                                        image:'/static/category-2.webp',
                                        label:'华为'
                                    },
                                    {
                                        image:'/static/category-2.webp',
                                        label:'华为'
                                    },
                                    {
                                        image:'/static/category-2.webp',
                                        label:'华为'
                                    },
                                    {
                                        image:'/static/category-2.webp',
                                        label:'华为'
                                    },
                                ]
                            })
                        break;
                        case '2':
                            res.json({
                                data:[
                                    {
                                        image:'/static/category-3.webp',
                                        label:'铨'
                                    },
                                    {
                                        image:'/static/category-3.webp',
                                        label:'铨'
                                    },
                                    {
                                        image:'/static/category-3.webp',
                                        label:'铨'
                                    },
                                    {
                                        image:'/static/category-3.webp',
                                        label:'铨'
                                    },
                                    {
                                        image:'/static/category-3.webp',
                                        label:'铨'
                                    },
                                ]
                            })
                        break;
                        case '3':
                            res.json({
                                data:[
                                    {
                                        image:'/static/category-4.webp',
                                        label:'7777777'
                                    },
                                    {
                                        image:'/static/category-4.webp',
                                        label:'7777777'
                                    },
                                    {
                                        image:'/static/category-4.webp',
                                        label:'7777777'
                                    },
                                    {
                                        image:'/static/category-4.webp',
                                        label:'7777777'
                                    },
                                    {
                                        image:'/static/category-4.webp',
                                        label:'7777777'
                                    },
                                ]
                            })
                        break;
                        case '4':
                            res.json({
                                data:[
                                    {
                                        image:'/static/category-5.webp',
                                        label:'666'
                                    },
                                    {
                                        image:'/static/category-5.webp',
                                        label:'666'
                                    },
                                    {
                                        image:'/static/category-5.webp',
                                        label:'666'
                                    },
                                    {
                                        image:'/static/category-5.webp',
                                        label:'666'
                                    },
                                    {
                                        image:'/static/category-5.webp',
                                        label:'666'
                                    },
                                ]
                            })
                        break;
                    }
                })
            }
        }
    },

    css: {
        loaderOptions: {
            stylus: {
                'resolve url': true,
                import: [
                    './src/theme'
                ]
            }
        }
    },

    pluginOptions: {
        'cube-ui': {
            postCompile: true,
            theme: true
        }
    }
}
